package _bye_util.logintrec;

/**
 * 
 * @author kagioglu
 */
public class Leaf implements TreeNode
{
    private int value;
    
    public Leaf( int value ) {
        this.value = value;
    }
    
    public int size()
    {
        return 1;
    }
    
    public int depth()
    {
        return 0;
    }
    
    public TreeNode newInt( int lowerBound, int upperBound, Ref newInt )
    {
        if ( this.value == lowerBound )
        {
            newInt.value = lowerBound + 1;
            return new Branch( this, lowerBound + 1, new Leaf( newInt.value ) );
        }
        else
        {
            newInt.value = lowerBound;
            return new Branch( new Leaf( newInt.value ), lowerBound + 1, this );
        }
    }
    
    public TreeNode recycleInt( int value )
    {
        if ( this.value == value )
        {
            return null;
        }
        else
        {
            throw new RuntimeException( "value missing" );
        }
    }
    
    public Branch shortenLeft( Branch parent )
    {
        throw new UnsupportedOperationException();
    }
    
    public Branch shortenRight( Branch parent )
    {
        throw new UnsupportedOperationException();
    }
}
